Building Web applicationI with Delphi
- To start new Web application click File/New then choose Web Server Application.
Select for example CGI stand-alone executable. Click Save All button, name the main
form (Testf.pas) and the project (Test.dpr).
- Right click on Actions (wich exists in WebModule1) then click Add Item.
- Click on the new item you have created (WebActionItem1) then press F11 to display
it's properties.
- Select True on Default property.
- Set the Output directory to the CGI directory, for example it can be C:\CGI, in
this directory the application exe file of CGI will be located.
- On events page double click in OnAction event. The most important parameters in
OnAction event are:
1. Response: enables you to send the HTML response to the client and settings such
as cookies.
2. Request: contains information from client side such as remote host name, remote
IP Address, Query, and submitted data fields.
- At OnAction event write this statement:
Response.Content:= 'Hello World';
- Run this example from the browser, the address can be for example: //localhost/cgi/Test.exe
If you want to run this CGI from another computer in the network you must write
your computer name, for example if your computer name is DelphiProgrammer you can
write in the address edit box: //DelphiProgrammer/cgi/test.exe
If for any reason this didn't work and you cann't access the comptuer name from
another computer in the network (may be there an error in WINS) you can write the
IP address instead of computer name such as:
//212.0.134.37/cgi/test.exe
Instead of LocalHost you can write loop back IP address, 127.0.0.1. Actually LocalHost always
resolved into the loop back address (127.0.0.1)
Content property is the HTML page which will be displayed after calling the CGI,
so that you can write a complete HTML page in Content property such as:
Response.Content:= 'This is a test of Delphi CGI
' +
'Bold text
Underlined
' +
'Time in server is: ' +
DateTimeToStr(Now) + '';